package student.view;

import req.StudentRequest;
import res.TableDTO;
import service.StudentService;
import service.impl.StudentServiceImpl;
import student.view.MainViewTable.MainViewTable;
import student.view.MainViewTable.MainViewTableModel;
import util.DimensionUtil;

import javax.swing.*;
import java.awt.*;
import java.util.Vector;

public class MainView extends JFrame {
    JPanel northPanel=new JPanel();
    JButton addBtn=new JButton("增加");
    JButton updateBtn=new JButton("修改");
    JButton delBtn=new JButton("删除");
    JTextField searchTxt=new JTextField(15);
    JButton searchBtn=new JButton("查询");
    JPanel sourthPanel=new JPanel();
    JButton preBtn=new JButton("上一页");
    JButton nextBtn=new JButton("下一页");
    MainViewTable mainViewTable=new MainViewTable();
    private int pageNow=1;
    private int pageSize=10;
    public MainView(){
        super("学生成绩管理系统");
        Container contentPane=getContentPane();
        northPanel.add(addBtn);
        northPanel.add(updateBtn);
        northPanel.add(delBtn);
        northPanel.add(searchTxt);
        northPanel.add(searchBtn);
        contentPane.add(northPanel,BorderLayout.NORTH);
        sourthPanel.add(preBtn);
        sourthPanel.add(nextBtn);
        contentPane.add(sourthPanel,BorderLayout.SOUTH);
        StudentService studentService=new StudentServiceImpl();
        StudentRequest request=new StudentRequest();
        request.setPageNow(pageNow);
        request.setPageSize(pageSize);
        request.setSearchKey(searchTxt.getText().trim());
        TableDTO tableDTO=studentService.retrieveSrudents(request);
        Vector<Vector<Object>> data=tableDTO.getData();
        MainViewTableModel mainViewTableModel=MainViewTableModel.assembleModel(data);
        mainViewTable.setDataModel(mainViewTableModel);
        JScrollPane jScrollPane=new JScrollPane(mainViewTable);
        contentPane.add(jScrollPane,BorderLayout.CENTER);
        setBounds(DimensionUtil.getBounds());
        setExtendedState(JFrame.MAXIMIZED_BOTH);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setVisible(true);
        setResizable(true);
    }

    public static void main(String[] args) {
        new MainView();
    }
}
